import cv2
cap = cv2.VideoCapture('./data-videos/traffic.mp4')
fps =int(cap.get(cv2.CAP_PROP_FPS))
size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),
int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
videoWriter = cv2.VideoWriter('video.avi', cv2.VideoWriter_fourcc('I','4','2','0'), fps, size)
ret, frame = cap.read()
while(ret):
    # 展示一帧
    cv2.imshow("capture", frame)
    videoWriter.write(frame)
    cv2.waitKey(fps)
    ret,frame = cap.read()
cap.release()
cv2.destroyAllWindows()

# import numpy as np
# import matplotlib.pyplot as plt
# import pylab
# import imageio
# import skimage.io
# import numpy as np  
# import cv2  

# cap = cv2.VideoCapture(r"D:\Data_Folder\git_rep\ImageAI\data-videos\traffic.mp4")  

# while(cap.isOpened()):  
#     ret, frame = cap.read()  
#     cv2.imshow('image', frame)  
#     k = cv2.waitKey(20)  
#     #q键退出
#     if (k & 0xff == ord('q')):  
#         break  

# cap.release()  
# cv2.destroyAllWindows()